# Create your views here.
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from models import Attachment
from cdsay.Attachment.form import AttachmentForm


def show_attachments(request):
    attachments = Attachment.objects.all()
    
    return render_to_response('show_attachments.html', locals())

def add_attachment(request):
    if request.method == 'POST':
        form = AttachmentForm(request.POST, request.FILES)
        form = AttachmentForm(request.FILES)
        form = AttachmentForm(request.POST)
        if form.is_valid():
            form.save()
            #return HttpResponseRedirect('../')
            return render_to_response('add_attachment.html', locals())
    else:
        form = AttachmentForm()

    return render_to_response('add_attachment.html', locals())

def modify_attachment(request):
    attachment_id = request.GET['id']
    attachment = Attachment.objects.get(pk=attachment_id)

    form = AttachmentForm(instance=attachment)

    return render_to_response('modify_attachment.html', locals())